package leetcode.每日一题;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author ：zsy
 * @date ：Created 2022/12/15 7:55 PM
 * @description：
 */
public class 用最少数量的箭引爆气球 {

    @Test
    public void test() {

    }

    class Solution {
        public int findMinArrowShots(int[][] points) {
            int n = points.length;
            if (n == 0) return 0;
            Arrays.sort(points, Comparator.comparingInt(o -> o[1]));
            int right = -1;
            int ans = 1;
            for (int i = 0; i < n; i++) {
                if (right == -1) {
                    right = points[i][1];
                } else {
                    if (points[i][0] > right) {
                        ans++;
                        right = points[i][1];
                    }
                }
            }
            return ans;
        }
    }
}
